package tool;

import javax.servlet.*;
import java.util.HashMap;

public class CustomServletContextListener implements ServletContextListener {
    /** 初始化上下文时，构建一个哈希映射和整型变量并将其设置为上下文的指定属性值 */
    @Override
    public void contextInitialized(ServletContextEvent servletContextEvent) {
        System.out.println("初始化应用程序");
        HashMap<String, String> users = new HashMap<>();
        ServletContext app = servletContextEvent.getServletContext();
        app.setAttribute("users", users);
        app.setAttribute("online", 0);
    }

    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {
        System.out.println("销毁应用程序");
    }
}
